package cn.w3cschool.chapter01.realm;

import org.apache.shiro.authc.*;
import org.apache.shiro.realm.Realm;

/**
 * Created by Administrator on 2017/11/12.
 */
public class MyRealm02 implements Realm {
    public String getName() {
        return "myRealm01";
    }

    public boolean supports(AuthenticationToken token) {
        return token instanceof UsernamePasswordToken;
    }

    public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        String username =(String)token.getPrincipal();
        String password = new String((char[])token.getCredentials());
        System.out.println(username+":"+password);
        if (!"wang".equals(username))
            throw new UnknownAccountException();
        if (!"123".equals(password))
            throw  new IncorrectCredentialsException();
        return new SimpleAuthenticationInfo(username,password,getName());
    }
}
